<template>
  <div class="singleInfo-wrapper">
    <div class="ui grid">
      <div class="twelve wide column"></div>
      <div class="four wide column">
        <div class="ui buttons">
          <button class="ui button " @click.prevent.stop="setOl(1)" :class="{active:ol1}">有效</button>
          <button class="ui button" :class="{active:ol0}" @click.prevent.stop="setOl(0)">无效</button>
        </div>
      </div>
    </div>
    <template v-if="modelInfo.riliDayMid==55">
      <mynum :field="recommended_price" @setVo="setVo"></mynum>
      <mynum :field="quantity" @setVo="setVo"></mynum>
    </template>
    <template v-else>
      <mynum :field="sale_price" @setVo="setVo"></mynum>

      <div class=" field" >
        <label for="">分成</label>
        <div class="ui  segment inline fields" >
          <mynum :field="fc_serv" class="inlineField" @setVo="setVo"></mynum>
          <mynum :field="fc_serv_up" class="inlineField" @setVo="setVo"></mynum>
          <mynum :field="fc_sp" class="inlineField" @setVo="setVo"></mynum>
        </div>
      </div>
      <div class="ui segment">
        <mydate :field="date_field" @setVo="setVo"></mydate>
        <mynum :field="delayed_sale_price" @setVo="setVo"></mynum>
        <div class="field" >
        <label for="">分成</label>
        <div class="ui  segment inline fields" >
          <mynum :field="delayed_fc_serv" class="inlineField" @setVo="setVo"></mynum>
          <mynum :field="delayed_fc_serv_up" class="inlineField" @setVo="setVo"></mynum>
          <mynum :field="delayed_fc_sp" class="inlineField" @setVo="setVo"></mynum>
        </div>
      </div>
      </div>
    </template>

    <!--<myenum :param="{}" v-if="enumField_ol.fval!==undefined" :field="enumField_ol" @setVo='setEnum'></myenum>-->
  </div>
</template>
<script type="text/ecmascript-6">
  import tool from 'src/util/tool'
  import logic from '_logic';
  import util from '_util/index';
  import myenum from 'components/field/enum';
  import mynum from 'components/field/num';
  import mydate from 'components/field/date';
  import RP from 'src/util/common/attr_rili';

  export default {
    data() {
      return {
        vo: {},
        ol0: false,
        ol1: false,
        date_field:{
          title:'起调日期',
          name:'valid_date'
        },
        fc_serv:{
          title:'服务者',
          name:'fc_serv'
        },
        fc_sp:{
          title:'供应商',
          name:'fc_sp'
        },
        fc_serv_up:{
          title:'服务商',
          name:'fc_serv_up'
        },
        sale_price:{
          title:'售价(¥)',
          name:'sale_price'
        },
        delayed_fc_serv:{
          title:'服务者',
          name:'delayed_fc_serv'
        },
        delayed_fc_sp:{
          title:'供应商',
          name:'delayed_fc_sp'
        },
        delayed_fc_serv_up:{
          title:'服务商',
          name:'delayed_fc_serv_up'
        },
        delayed_sale_price:{
          title:'售价(¥)',
          name:'delayed_sale_price'
        },
        recommended_price:{
          title:'成本价(¥)',
          name:'recommended_price'
        },
        quantity:{
          title:'库存(份)',
          name:'quantity'
        },
        enumField_ol: {
          name: 'ol',
          title: '状态',
          enum_val: [
            '无效', '有效'
          ]
        },
      }
    },
    created() {
      this.vo = this.info||{};
      let farr = ['recommended_price','fc_serv','fc_sp','fc_serv_up','delayed_fc_serv','delayed_fc_sp','delayed_fc_serv_up','quantity','sale_price','delayed_sale_price'];
      this.date_field.fval = this.vo[this.date_field.name];
      farr.map(item=> {
        let tmp = 0;
        if(this.vo[item])
          tmp = item == 'quantity' ? this.vo[item] : this.vo[item] ;
        this[item].fval = tmp;
      });

      this.enumField_ol.fval = this.vo['ol'] || 1;
      RP.ol_init(this)
    },
    mounted() {

    },
    computed: {},
    methods: {
      setVo(name,val){
//        this.vo[name] = val;
        this.$set(this.vo, name, val);
      },
      setOl(flag){
        RP.setOl(this, flag);
      },
      setEnum(name, val) {
        this.vo[name] = val;
      },
    },
    watch: {
      vo: {
        handler:function (val, old) {
            this.$emit('setInfo', val, this.product_id)
        },
        deep:true
      },
      ol: function (val, old) {
          RP.ol_init(this)
      },
    },
    components: {myenum,mydate,mynum},
    props: ['product_id', 'info','modelInfo', 'ol']
  }
</script>
<style rel="stylesheet/less" scoped lang="less">@dir: "common/";
.singleInfo-wrapper {
}
</style>
